package com.yanqu.road.server.cmd.orewar.cross;

import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.pb.orewar.OreWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.orewar.OreWarMgr;
import com.yanqu.road.server.manger.config.PatronsMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.property.Property;

import java.math.BigInteger;
import java.util.List;

@Cmd(code = Protocol.S_CROSS_ORE_WAR_PIT_RECALL, desc = "撤回矿坑情况跨服返回")
public class CrossRecallPitRespCmd extends AbstractCommand {

	private int activityId;
	private int pitId;
	private long rewardValue;
	private String patronsInfoStr;//坑位上的门客信息
	private int rewardMin;
	private int groupId;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		OreWarProto.CrossOrePitRecallRespMsg crossRespMsg = OreWarProto.CrossOrePitRecallRespMsg.parseFrom(packet.getBytes());
		ret = crossRespMsg.getRet();
		activityId = crossRespMsg.getActivityId();
		pitId = crossRespMsg.getPitId();
		rewardValue = crossRespMsg.getReward();
		patronsInfoStr = crossRespMsg.getPatronsInfoStr();
		rewardMin = crossRespMsg.getRewardMin();
		groupId = crossRespMsg.getGroupId();

		OreWarProto.OrePitWithdrawRespMsg.Builder resMsg =  OreWarProto.OrePitWithdrawRespMsg.newBuilder();
		resMsg.setRet(ret);
		if(ret == 0){
			List<Integer> patronIdList = PatronsMgr.parsePatronInfoStrToIdList(patronsInfoStr);
			OreWarMgr.addCrossRecallReward(activityId,player,pitId,rewardValue,rewardMin,patronIdList,groupId);
			Property reward = new Property(GameConfig.ACTIVITY_ORE_WAR_OUTPUT_GOODSID, BigInteger.valueOf(rewardValue));
			resMsg.setReward(rewardValue);
		}

		player.sendPacket(Protocol.U_ORE_WAR_RECALL_PIT, resMsg);
	}

	@Override
	public void sendData(GamePlayer player) {

	}
}
